function show_add_subcategory()
{
    $('#add-subcategory').dialog({
        modal: true,
        width: 550,
        height: 410,
        buttons: {'Сохранить' : function() {$('#add-subcategory form').submit();}, 'Отмена' : function() {$(this).dialog('close');}}
    });
}

function show_edit_subcategory(subcategory_id)
{
    $.post('/ajax/categories/get_subcategory', {subcategory_id: subcategory_id},
        function(data) {
            $('#edit-subcategory').find('select[name = category_id]').find('option[value = ' + data.subcategory.category_id + ']').attr('selected', 'selected');
            $('#edit-subcategory').find('input[name = title]').val(data.subcategory.title);
            $('#edit-subcategory').find('input[name = url]').val(data.subcategory.url);
            $('#edit-subcategory').find('input[name = subcategory_id]').val(data.subcategory.subcategory_id);
            
            $('#edit-subcategory').dialog({
                modal: true,
                width: 550,
                height: 410,
                buttons: {'Сохранить' : function() {$('#edit-subcategory form').submit();}, 'Отмена' : function() {$(this).dialog('close');}}
            });  
    }, 'json');
}

function check_subcategory_form(form)
{
    var title = $(form).find('input[name = title]').val();
    var url   = $(form).find('input[name = url]').val();
    
    if(title && url)
        return true;
    
    $('#subcategory-form-error').dialog('open');
    
    return false;
}